@extends('admin.common.base-master')

@section('html-head')
    <link href="{{url('css/admin/pagenum.css')}}" rel="stylesheet" />
@endsection

@section('html-body')
    <!-- content start -->
    <div id="content">
        <!-- cur-position start -->
        <div id="cur-position">
            <span class="tit">当前位置：</span>
            <a href="#">用户管理</a>
        </div>
        <!-- cur-position end -->

        <!--二级目录-->
        @include('admin.common.user-header')

        <div class="filter-box clearfix">
            <div class="fl" style="display: inline-flex">
                <div class="sx">
                    <span>手机号码：</span>
                    <input class="gg-ipt" style="width: 180px;height: 26px" placeholder="请输入手机号码" name="phone" id="phone" value="" />
                </div>

                <div class="sx">
                    <button class="sx-btn" id="sx_btn">搜索</button>
                </div>
            </div>
        </div>
        <div class="table-box">
            <table class="table">
                <thead>
                <tr>
                    <th>ID</th>
                    <th>用户手机</th>
                    <th>企业名称</th>
                    <th>企业电话</th>
                    <th>法人姓名</th>
                    <th>营业执照</th>
                    <th>营业执照照片</th>
                    <th>创建时间</th>
                    <th>认证情况</th>
                    <th>操作</th>
                </tr>
                </thead>
                <tbody id="fansinfo">
                @if(count($companyAuths) > 0)
                    @foreach($companyAuths as $companyAuth)
                        <tr>
                            <td>{{$companyAuth->id}}</td>
                            <td>{{$companyAuth->phone}}</td>
                            <td>{{$companyAuth->name}}</td>
                            <td>{{$companyAuth->contact_phone}}</td>
                            <td>{{$companyAuth->legal_person_name}}</td>
                            <td>{{$companyAuth->license}}</td>
                            <td class="account-td" style="width: 20px;">
                                <span class="photo">
                                    <a href="{{$companyAuth->license_img_url}}" target="_blank"><img src="{{$companyAuth->license_img_url}}" alt=""></a>
                                </span>
                            </td>
                            <td>{{$companyAuth->created_at}}</td>
                            <td>
                            @if($companyAuth->company_auth == 0 && $companyAuth->company_auth != null)
                                未认证
                            @elseif($companyAuth->company_auth == 1 && $companyAuth->company_auth != null)
                                <p style="color: green;">已认证</p>
                            @elseif($companyAuth->company_auth == 2 && $companyAuth->company_auth != null)
                                <p style="color: orange;">认证中</p>
                            @elseif($companyAuth->company_auth == 3 && $companyAuth->company_auth != null)
                                <p style="color: red;">认证失败</p>
                            @endif
                            </td>
                            <td>
                                <a href="javascript:;" onclick="upPop({{$companyAuth->user_id}})" style="color:olive;">设置认证状态</a>
                            </td>
                        </tr>
                    @endforeach
                @endif
                </tbody>
            </table>
            <?php echo $companyAuths->render(); ?>
        </div>
    </div>

    <div class="upPop-box">
        <div class="backdrop"></div>
        <div id="upPop" class="info-pop tixian">
            <input type="hidden" name="id" id="classifyid" value=""/>
            <a class="close" href="javascript:void(0);"></a>
            <h3>设置认证状态</h3>

            <div class="fill-list">
                <span class="fill-tit">分类层级：</span>
                <select name="company_auth" id="company_auth">
                    <option value="1">通过</option>
                    <option value="3">不通过</option>
                </select>
            </div>

            <input type="hidden" name="id" id="user_id" />
            <div class="fill-list">
                <span class="fill-tit">&nbsp;</span>
                <input class="fill-submit" type="button" id="subThisForm" value="提交">
            </div>
        </div>
    </div>

    <script>
        function upPop(user_id){
            $('#user_id').val(user_id);
            $('.upPop-box').upPop();

        }
        $(function(){
            $('#sx_btn').click(function () {
                var phone       = $("#phone").val();

                window.location.href = "{{route('Admin.Home.companyAuthList')}}?phone="+phone;
            });


            $(document).on('click', '#subThisForm', function () {
                var userId     = $('#user_id').val();
                var companyAuth     = $('#company_auth').val();

                $.ajax({
                    url: '{{route("Api.Admin.sys.setCompanyAuth")}}',
                    type: 'post',
                    dataType: 'json',
                    data: {
                        user_id:userId,
                        company_auth:companyAuth
                    },
                    success: function (obj) {
                        if (obj.level == "success") {
                            noty({
                                text: obj.message, type: obj.level, timeout: 600,
                                callback: {
                                    afterClose:function(){
                                        window.location.reload();
                                    }
                                }
                            });
                        } else if (obj.level == "error") {
                            noty({text: obj.message, type: obj.level, timeout: 600});
                        }

                    },
                    error: function (obj) {
                        console.log(obj);
                    }
                });
            });
        });

    </script>
    <!-- content end -->

@endsection